package com.dominator.repository;

import com.dominFramework.core.dao.SqlDao;
import com.dominFramework.core.id.SystemIdUtils;
import com.dominFramework.core.typewrap.Dto;
import com.dominFramework.core.typewrap.Dtos;
import com.dominator.mybatis.dao.T_entrance_ticketDao;
import com.dominator.mybatis.dao.T_entrance_ticketPO;
import com.dominator.utils.api.ApiUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public class DaoEntranceTicket {

    @Autowired
    T_entrance_ticketDao entranceDao;

    @Autowired
    SqlDao sqlDao;

    public int addTicket(Dto dto){
        ApiUtils.checkParam(dto,"userId,ticketType,quantity,totalAmount,userName,visiteDate,sn");
        T_entrance_ticketPO model = new T_entrance_ticketPO();
        model.setId(SystemIdUtils.uuid());
        model.setTicket_name(dto.getString("ticketName"));
        model.setTicket_type(dto.getString("ticketType"));
        model.setQuantity(dto.getInteger("quantity"));
        model.setPay_money(dto.getBigDecimal("totalAmount"));
        model.setPoints(dto.getBigDecimal("points"));
        model.setUser_name(dto.getString("userName"));
        model.setUser_idcard(dto.getString("userIdCard"));
        model.setUser_phone(dto.getString("userPhone"));
        model.setVisite_date(dto.getDate("visiteDate"));
        model.setSn(dto.getString("sn"));
        model.setUser_id(dto.getString("userId"));
        model.setCreate_time(new Date());
        model.setStatus("0");//状态 未同步0 已同步1
        model.setIs_valid("1");
        model.setIs_paid("0");

        return entranceDao.insert(model);
    }

    public T_entrance_ticketPO selectBySn(Dto dto){
        return (T_entrance_ticketPO)sqlDao.selectOne("EnTicket.selectBySn",dto);
    }

    public int update(T_entrance_ticketPO po){

        return entranceDao.updateByKey(po);
    }
}
